<!--
 * @Description: 评价标签
 * @Author: xiao li
 * @Date: 2021-07-04 13:00:37
 * @LastEditTime: 2022-08-03 17:26:59
 * @LastEditors: xiao li
-->

<template>
  <div class="lb-shop-refund">
    <top-nav />
    <div class="page-main">
      <el-row class="page-search-form">
        <el-form
          @submit.native.prevent
          :inline="true"
          :model="searchForm"
          ref="searchForm"
        >
          <el-form-item label="技师名称" prop="coach_name">
            <el-input
              v-model="searchForm.coach_name"
              placeholder="请输入技师名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="服务名称" prop="goods_name">
            <el-input
              v-model="searchForm.goods_name"
              placeholder="请输入服务名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="星级" prop="star">
            <el-select
              @change="getTableDataList(1)"
              v-model="searchForm.star"
              placeholder="请选择"
            >
              <el-option
                v-for="item in statusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <lb-button
              size="medium"
              type="primary"
              icon="el-icon-search"
              style="margin-right: 5px"
              @click="getTableDataList(1)"
              >{{ $t('action.search') }}</lb-button
            >
            <lb-button
              size="medium"
              icon="el-icon-refresh-left"
              style="margin-right: 5px"
              @click="resetForm('searchForm')"
              >{{ $t('action.reset') }}</lb-button
            >
          </el-form-item>
        </el-form>
      </el-row>
      <el-table
        v-loading="loading"
        :data="tableData"
        :header-cell-style="{ background: '#f5f7fa', color: '#606266' }"
        style="width: 100%"
      >
        <el-table-column
          prop="id"
          label="ID"
          width="80"
          fixed
        ></el-table-column>
        <el-table-column
          prop="goods_info_text"
          width="300"
          label="服务项目信息"
        >
          <template slot-scope="scope">
            <div
              class="pb-sm"
              v-for="(citem, cindex) in scope.row.order_goods"
              :key="cindex"
            >
              <div class="flex-warp pt-md">
                <lb-image class="avatar radius-5" :src="citem.goods_cover" />
                <div
                  class="flex-1 f-caption c-caption ml-md"
                  style="width: 210px"
                >
                  <div class="flex-between">
                    <div
                      class="f-paragraph c-title ellipsis"
                      :class="[{ 'max-300': citem.refund_num > 0 }]"
                      style="line-height: 1.2; margin-bottom: 4px"
                    >
                      {{ citem.goods_name }}
                    </div>
                    <div
                      class="f-caption c-warning"
                      v-if="citem.refund_num > 0"
                    >
                      已退x{{ citem.refund_num }}
                    </div>
                  </div>
                  <div class="flex-between f-caption mt-md">
                    <div class="c-warning ml-md">¥{{ citem.price }}</div>
                    <div>x{{ citem.goods_num || 1 }}</div>
                  </div>
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="user_id" label="客户ID"></el-table-column>
        <el-table-column prop="nickName" label="客户昵称"></el-table-column>
        <el-table-column prop="coach_name" label="技师"></el-table-column>
        <el-table-column prop="star" label="评价星级" min-width="200">
          <template slot-scope="scope">
            <div class="flex-warp">
              <i
                class="iconfont iconyduixingxingkongxin c-caption mr-sm"
                :class="[
                  { 'iconyduixingxingshixin c-danger': index < scope.row.star }
                ]"
                v-for="(item, index) in 5"
                :key="index"
              ></i>
            </div> </template
        ></el-table-column>
        <el-table-column prop="text" label="评价内容" min-width="200">
        </el-table-column>
        <el-table-column prop="lable_text" label="评价标签" min-width="300">
          <template slot-scope="scope">
            <el-tag
              class="mr-md mb-md"
              v-for="(item, index) in scope.row.lable_text"
              :key="index"
              >{{ item }}</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column prop="create_time" min-width="120" label="评价时间">
          <template slot-scope="scope">
            <div>{{ scope.row.create_time | handleTime(1) }}</div>
            <div>{{ scope.row.create_time | handleTime(2) }}</div>
          </template>
        </el-table-column>
        <el-table-column width="90px" label="操作">
          <template slot-scope="scope">
            <div class="table-operate">
              <lb-button
                size="mini"
                plain
                type="danger"
                @click="confirmDel(scope.row.id)"
                >{{ $t('action.delete') }}</lb-button
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
      <lb-page
        :batch="false"
        :page="searchForm.page"
        :pageSize="searchForm.limit"
        :total="total"
        @handleSizeChange="handleSizeChange"
        @handleCurrentChange="handleCurrentChange"
      >
      </lb-page>
    </div>
  </div>
</template>

<script>
import moment from 'moment'
export default {
  data () {
    return {
      statusOptions: [
        {
          label: '全部',
          value: 0
        },
        {
          label: '五星',
          value: 5
        },
        {
          label: '四星',
          value: 4
        },
        {
          label: '三星',
          value: 3
        },
        {
          label: '二星',
          value: 2
        },
        {
          label: '一星',
          value: 1
        }
      ],
      statusType: {
        1: '退款申请中',
        2: '同意退款',
        3: '拒绝退款'
      },
      loading: false,
      searchForm: {
        page: 1,
        limit: 10,
        coach_name: '',
        goods_name: '',
        star: 0
      },
      tableData: [],
      total: 0,
      dialogRefund: false,
      refundId: '',
      refundMoney: '',
      refundTotalMoney: '',
      lockRefund: false
    }
  },
  created () {
    this.getTableDataList()
  },
  methods: {
    resetForm (form) {
      this.$refs[form].resetFields()
      this.getTableDataList(1)
    },
    handleSizeChange (val) {
      this.searchForm.limit = val
      this.handleCurrentChange(1)
    },
    handleCurrentChange (val) {
      this.searchForm.page = val
      this.getTableDataList()
    },
    async getTableDataList (flag) {
      if (flag) this.searchForm.page = 1
      this.loading = true
      let { searchForm } = this
      let { code, data } = await this.$api.shop.commentList(searchForm)
      this.loading = false
      if (code !== 200) return
      this.tableData = data.data
      this.total = data.total
    },
    confirmDel (id) {
      this.$confirm(this.$t('tips.confirmDelete'), this.$t('tips.reminder'), {
        confirmButtonText: this.$t('action.comfirm'),
        cancelButtonText: this.$t('action.cancel'),
        type: 'warning'
      })
        .then(() => {
          this.updateItem(id, -1)
        })
        .catch(() => { })
    },
    async updateItem (id, status) {
      this.$api.shop.commentUpdate({ id, status }).then((res) => {
        if (res.code === 200) {
          this.$message.success(
            this.$t(status === -1 ? 'tips.successDel' : 'tips.successOper')
          )
          if (status === -1) {
            this.searchForm.page =
              this.searchForm.page <
                Math.ceil((this.total - 1) / this.searchForm.limit)
                ? this.searchForm.page
                : Math.ceil((this.total - 1) / this.searchForm.limit)
            this.getTableDataList()
          }
        } else {
          if (status === -1) return
          this.getTableDataList()
        }
      })
    }
  },
  filters: {
    handleTime (val, type) {
      let time = type === 1 ? moment(val * 1000).format('YYYY-MM-DD') : type === 2 ? moment(val * 1000).format('HH:mm:ss') : moment(val * 1000).format('YYYY-MM-DD HH:mm:ss')
      return time
    }
  }
}
</script>

<style lang="scss" scoped>
.lb-shop-refund {
  .page-main {
    width: 100%;

    .el-select,
    .el-input-number,
    .el-input {
      width: 200px;
    }
  }
}

.none {
  display: none;
}
</style>
<style media="print">
.none {
  display: block;
}
</style>
